//
// Created by guoshunw on 23-12-14.
//

#include "utils.h"

#include <iomanip>

std::string to_hex(uint8_t *data, size_t size, size_t width = 16) {
    std::stringstream ss;
    for (auto i = 0; i < size;) {
        if (i % width == 0) {
            ss << std::setw(6) << std::dec << std::setfill('0') << i << "  ";
        }
        ss << std::setw(2) << std::setfill('0') << std::hex << +data[i] << " ";
        if (++i % width == 0) ss << std::endl;
    }
    ss << std::endl;
    return ss.str();
}
